from allpairspy import AllPairs

from api_py.enums.cookie import Cookie
from api_py.generate_case.template import template_case
from api_py.utils.file_sys import write_json

page = [
    {"value": "", "description": "页码参数为空"},
    {"value": 0, "description": "页码参数为0"},
    {"value": "abc", "description": "页码参数不合法"},
]

size = [
    {"value": "", "description": "条目参数为空"},
    {"value": 0, "description": "条目参数为0"},
    {"value": "1", "description": "条目参数为1"},
    {"value": "abc", "description": "条目参数不合法"},
]

cookies = [
    {"value": Cookie.ADMIN_COOKIE.value, "description": "管理员登录"},
    {"value": Cookie.SUPERVISOR_COOKIE.value, "description": "督导登录"},
    {"value": Cookie.COUNSELOR_COOKIE.value, "description": "咨询师登录"},
    {"value": Cookie.WEIXIN_COOKIE.value, "description": "微信访客登录"},
    {"value": Cookie.NULL_COOKIE.value, "description": "未登录"},
]

# 检测权限用例
body = [
    {"value": 0, "description": "页码参数为0"},
    {"value": "1", "description": "条目参数为1"},
]



def case06_user_list(api_type):
    json_result = {}
    parameters = [page, size]
    i = 0

    for pairs in AllPairs(parameters):
        case = template_case()
        request = case["request"]
        wrap_data(request, pairs)
        # 设置请求头cookie
        request["headers"]["Cookie"] = cookies[0]

        json_result[i] = case
        i += 1

    for cookie in cookies:
        case = template_case()
        request = case["request"]
        wrap_data(request, body)
        # 设置请求头cookie
        request["headers"]["Cookie"] = cookie

        json_result[i] = case
        i += 1


    write_json(api_type.value[0]["file_name"], json_result)


def wrap_data(request, data):
    request["params"]["page"] = data[0]
    request["params"]["size"] = data[1]